<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <style>
    #main {
      border: 1px solid #000;
    }
  </style>
  <title>Document</title>
</head>

<body>
  <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
  <div id="main" style="width: 700px; height: 600px"></div>
  <!-- 下包+导包 -->
  <script src="./lib/echarts.min.js"></script>
  <script>
    // 食物数据
    const foodArr = [
      { name: '西兰花', price: 150 },
      { name: '西瓜', price: 230 },
      { name: '西葫芦', price: 224 },
      { name: '西北风', price: 34 },
      { name: '西红柿', price: 135 },
      { name: '西芹', price: 147 },
      { name: '西洋菜', price: 260 }
    ]
    const chart = echarts.init(document.querySelector('#main'))
    const option = {
      title: {
        text: '菜价',
        left: 20,
        top: 20,
        textStyle: {
          fontSize: 25
        }
      },
      tooltip: {},
      legend: {
        data: ['销量']
      },
      xAxis: {
        data: foodArr.map(item => item.name),
        
      },
      yAxis: {},
      series: [
        {
          name: '销量',
          type: 'bar',
          data: foodArr.map(item => item.price)
        }
      ],
      color: ['#86cce9']
    }
    chart.setOption(option);
  </script>
</body>

</html>